package uk.ac.bbsrc.tgac.miso.webapp.controller;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import uk.ac.bbsrc.tgac.miso.core.data.impl.OrderPurpose;
import uk.ac.bbsrc.tgac.miso.core.security.AuthorizationManager;
import uk.ac.bbsrc.tgac.miso.core.service.OrderPurposeService;
import uk.ac.bbsrc.tgac.miso.core.service.ProviderService;
import uk.ac.bbsrc.tgac.miso.dto.Dtos;
import uk.ac.bbsrc.tgac.miso.dto.OrderPurposeDto;

@Controller
@RequestMapping("/orderpurpose")
public class OrderPurposeController extends AbstractTypeDataController<OrderPurpose, OrderPurposeDto> {

  @Autowired
  private OrderPurposeService orderPurposeService;

  @Autowired
  private AuthorizationManager authorizationManager;

  public OrderPurposeController() {
    super("Order Purposes", "orderpurpose", "orderpurpose");
  }

  @GetMapping("/list")
  public ModelAndView list(ModelMap model) throws IOException {
    return listStatic(orderPurposeService.list(), model);
  }

  @GetMapping("/bulk/new")
  public ModelAndView create(@RequestParam("quantity") Integer quantity, ModelMap model) throws IOException {
    return bulkCreate(quantity, model);
  }

  @GetMapping("/bulk/edit")
  public ModelAndView edit(@RequestParam("ids") String idString, ModelMap model) throws IOException {
    return bulkEdit(idString, model);
  }

  @Override
  protected AuthorizationManager getAuthorizationManager() {
    return authorizationManager;
  }

  @Override
  protected ProviderService<OrderPurpose> getService() {
    return orderPurposeService;
  }

  @Override
  protected OrderPurposeDto toDto(OrderPurpose object) {
    return Dtos.asDto(object);
  }

  @Override
  protected OrderPurposeDto makeDto() {
    return new OrderPurposeDto();
  }

}
